package net.hn.hnms.biz.safety.trinity.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.safety.trinity.service.HiddenDangerRecordService;
import net.hn.hnms.biz.safety.trinity.service.NormCheckScoreService;
import net.hn.hnms.biz.safety.trinity.service.RiskControlService;
import net.hn.hnms.biz.safety.trinity.service.WorkSafetyViolationService;
import net.hn.hnms.biz.safety.trinity.until.Dictionaries;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import net.hn.hnms.biz.api.safety.trinity.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 智呈物联 pan'sx
 * 2022/7/25 11:22
 * 1.0 version
 */
@RestController
@RequestMapping("manage/double")
@Api(value = "安全风险双预控控制器", tags = {"安全风险双预控"})
public class ManageDoubleController {

    HiddenDangerRecordService hiddenDangerRecordService;

    RiskControlService riskControlService;

    WorkSafetyViolationService workSafetyViolationService;

    NormCheckScoreService normCheckScoreService;

    @Autowired
    public void setHiddenDangerRecordService(HiddenDangerRecordService hiddenDangerRecordService) {
        this.hiddenDangerRecordService = hiddenDangerRecordService;
    }

    @Autowired
    public void setRiskControlService(RiskControlService riskControlService) {
        this.riskControlService = riskControlService;
    }

    @Autowired
    public void setWorkSafetyViolationService(WorkSafetyViolationService workSafetyViolationService) {
        this.workSafetyViolationService = workSafetyViolationService;
    }

    @Autowired
    public void setNormCheckScoreService(NormCheckScoreService normCheckScoreService) {
        this.normCheckScoreService = normCheckScoreService;
    }

    @GetMapping("dangerInformation")
    @ApiOperation("根据煤矿编码获取当天隐患信息")
    @AutoSetMineCode
    public R<DangerInfoVo> hiddenDanger(String mineCode) {
        if (Dictionaries.GAOTOUYAOMINECODE.equals(mineCode)){
            return R.ok(hiddenDangerRecordService.gaoTouYaoHiddenDanger(mineCode));
        }else {
            return R.ok(hiddenDangerRecordService.hiddenDanger(mineCode));
        }
    }

    @GetMapping("riskControl")
    @ApiOperation("风险管控")
    @AutoSetMineCode
    public R<RiskControlVo> riskControl(String mineCode) {
        //todo
        return R.ok(riskControlService.riskControl(mineCode));
    }
    @GetMapping("threeViolations")
    @ApiOperation("三违管理")
    public R<TreeViolationsManagementVo> threeViolations() {
        return R.ok(workSafetyViolationService.threeViolations());
    }
    @GetMapping("hiddenDangerCheck")
    @ApiOperation("隐患排查")
    @AutoSetMineCode
    public R<HiddenDangerCheckVo> hiddenDangerCheck(String mineCode){
        if (Dictionaries.GAOTOUYAOMINECODE.equals(mineCode)){
            return R.ok(hiddenDangerRecordService.gaotouyaoHiddenDangerCheck(mineCode));
        }else {
            return R.ok(hiddenDangerRecordService.hiddenDangerCheck(mineCode));
        }
    }

    @GetMapping("standardizedManagement")
    @ApiOperation("标准化管理 ")
    @AutoSetMineCode
    public R<StandardizedManagementVo> standardizedManagement(String name,String mineCode){
        //todo
        return R.ok(normCheckScoreService.standardizedManagement(name,mineCode));
    }

    @GetMapping(value = "getLevelNum")
    @ApiOperation(value = "获取各状态隐患数量-首页综合概览-安全隐患统计")
    @AutoSetMineCode
    public R<HiddenDangerLevelNumVo> getLevelNum(String mineCode){
        if (Dictionaries.GAOTOUYAOMINECODE.equals(mineCode)){
            return R.ok(hiddenDangerRecordService.getGaotouyaoLevelNum(mineCode));
        }
        return R.ok(hiddenDangerRecordService.getLevelNum(mineCode));
    }

    @GetMapping(value = "riskInfoList")
    @ApiOperation(value = "风险分析")
    @AutoSetMineCode
    public R<Map<String,Object>> riskInfoList(String mineCode){
        return R.ok(riskControlService.riskInfoList(mineCode));
    }

    @GetMapping(value = "dangerInfoList")
    @ApiOperation(value = "隐患分析")
    @AutoSetMineCode
    public R<Map<String,Object>> dangerInfoList(String mineCode){
        if (Dictionaries.GAOTOUYAOMINECODE.equals(mineCode)){
            return R.ok(hiddenDangerRecordService.gaoTouYaoDangerInfoList(mineCode));
        }else {
            return R.ok(hiddenDangerRecordService.dangerInfoList(mineCode));
        }
    }

    @GetMapping(value = "sumDangerCheck")
    @ApiOperation(value = "隐患统计数量")
    @AutoSetMineCode
    public R<Map<String,Object>> sumDangerCheck(String mineCode){
        return R.ok(hiddenDangerRecordService.sumDangerCheck(mineCode));
    }

    @GetMapping(value = "sumDangerLevelAndRiskLevel")
    @ApiOperation(value = "风险隐患各等级数量")
    @AutoSetMineCode
    public R<TrinityLevel> sumDangerLevelAndRiskLevel(String mineCode){
        TrinityLevel trinityLevel = new TrinityLevel();
        hiddenDangerRecordService.hiddenDangerLevel(trinityLevel,mineCode);
        riskControlService.riskLevelNum(trinityLevel,mineCode);
        return R.ok(trinityLevel);
    }

    @GetMapping(value = "getHiddenDangerCheckMonth")
    @ApiOperation(value = "近30天隐患新增以及闭环情况")
    @AutoSetMineCode
    public R<HiddenDangerCheckMonthVo> getHiddenDangerCheckMonth(String mineCode){
        return R.ok(hiddenDangerRecordService.getHiddenDangerCheckMonth(mineCode));
    }

    @GetMapping(value = "getHiddenDangerCheckYear")
    @ApiOperation(value = "近年隐患新增情况")
    @AutoSetMineCode
    public R<HiddenDangerCheckYearVo> getHiddenDangerCheckYear(String mineCode){
        if (Dictionaries.GAOTOUYAOMINECODE.equals(mineCode)){
            return R.ok(hiddenDangerRecordService.getGaoTouYaoHiddenDangerCheckYear(mineCode));
        }else {
            return R.ok(hiddenDangerRecordService.getHiddenDangerCheckYear(mineCode));
        }

    }

}
